/*
 * Copyright (c) 2011, Michael van der Westhuizen
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *    - Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *    - Redistributions in binary form must reproduce the above
 *      copyright notice, this list of conditions and the following
 *      disclaimer in the documentation and/or other materials provided
 *      with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
#ifndef PYXMLSEC1_KEYS_C_MCVDW_20110126
#define PYXMLSEC1_KEYS_C_MCVDW_20110126

#include "pyxmlsec.h"

#include <xmlsec/keys.h>



static PyObject * xmlsec1_xmlSecKeyUseWithInitialize(PyObject * self, PyObject * arg)
{
    xmlSecKeyUseWithPtr keyUseWith;

    if (NULL == (keyUseWith = xmlsec1mod_unwrap_xmlSecKeyUseWithPtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyUseWithPtr);
        return NULL;
    }

    if (0 != xmlSecKeyUseWithInitialize(keyUseWith))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyUseWithInitialize);
        return NULL;
    }

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyUseWithFinalize(PyObject * self, PyObject * arg)
{
    xmlSecKeyUseWithPtr keyUseWith;

    if (NULL == (keyUseWith = xmlsec1mod_unwrap_xmlSecKeyUseWithPtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyUseWithPtr);
        return NULL;
    }

    xmlSecKeyUseWithFinalize(keyUseWith);
    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyUseWithReset(PyObject * self, PyObject * arg)
{
    xmlSecKeyUseWithPtr keyUseWith;

    if (NULL == (keyUseWith = xmlsec1mod_unwrap_xmlSecKeyUseWithPtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyUseWithPtr);
        return NULL;
    }

    xmlSecKeyUseWithReset(keyUseWith);
    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyUseWithCopy(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecKeyUseWithPtr dst;
    xmlSecKeyUseWithPtr src;

    static char * kwlist[] = {"dst", "src", NULL};

    arg1 = arg2 = NULL;
    dst = src = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (dst = xmlsec1mod_unwrap_xmlSecKeyUseWithPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyUseWithPtr);
        return NULL;
    }

    if (NULL == (src = xmlsec1mod_unwrap_xmlSecKeyUseWithPtr(arg2)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyUseWithPtr);
        return NULL;
    }

    if (0 != xmlSecKeyUseWithCopy(dst, src))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyUseWithCopy);
        return NULL;
    }

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyUseWithCreate(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlChar * application;
    xmlChar * identifier;
    xmlSecKeyUseWithPtr ptr;
    PyObject * ret;

    static char * kwlist[] = {"application", "identifier", NULL};

    arg1 = arg2 = ret = NULL;
    application = identifier = NULL;
    ptr = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    } 

    if (0 != xmlsec1_UnicodeOrBytesToXmlCharPtr(arg1, &application, NULL))
    {
        ENSURE_EXCEPTION_SET(xmlsec1_UnicodeOrBytesToXmlCharPtr);
        return NULL;
    }

    if (0 != xmlsec1_UnicodeOrBytesToXmlCharPtr(arg2, &identifier, NULL))
    {
        ENSURE_EXCEPTION_SET(xmlsec1_UnicodeOrBytesToXmlCharPtr);
        xmlFree(application);
        return NULL;
    }

    if (NULL == (ptr = xmlSecKeyUseWithCreate(application, identifier)))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyUseWithCreate);
        xmlFree(application);
        xmlFree(identifier);
        return NULL;
    }

    xmlFree(application);
    xmlFree(identifier);

    if (NULL == (ret = xmlsec1mod_wrap_xmlSecKeyUseWithPtr(ptr)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_wrap_xmlSecKeyUseWithPtr);
        xmlSecKeyUseWithDestroy(ptr);
        return NULL;
    }

    return ret;
}



static PyObject * xmlsec1_xmlSecKeyUseWithDuplicate(PyObject * self, PyObject * arg)
{
    xmlSecKeyUseWithPtr keyUseWith;
    xmlSecKeyUseWithPtr ptr;
    PyObject * ret;

    if (NULL == (keyUseWith = xmlsec1mod_unwrap_xmlSecKeyUseWithPtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyUseWithPtr);
        return NULL;
    }

    if (NULL == (ptr = xmlSecKeyUseWithDuplicate(keyUseWith)))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyUseWithDuplicate);
        return NULL;
    }

    if (NULL == (ret = xmlsec1mod_wrap_xmlSecKeyUseWithPtr(ptr)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_wrap_xmlSecKeyUseWithPtr);
        xmlSecKeyUseWithDestroy(ptr);
        return NULL;
    }

    return ret;
}



static PyObject * xmlsec1_xmlSecKeyUseWithDestroy(PyObject * self, PyObject * arg)
{
    xmlSecKeyUseWithPtr keyUseWith;

    if (NULL == (keyUseWith = xmlsec1mod_unwrap_xmlSecKeyUseWithPtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyUseWithPtr);
        return NULL;
    }

    xmlSecKeyUseWithDestroy(keyUseWith);
    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyUseWithSet(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    PyObject * arg3;
    xmlSecKeyUseWithPtr keyUseWith;
    xmlChar * application;
    xmlChar * identifier;

    static char * kwlist[] = {"keyUseWith", "application", "identifier", NULL};

    arg1 = arg2 = arg3 = NULL;
    keyUseWith = NULL;
    application = identifier = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOO", kwlist, &arg1, &arg2, &arg3))
    {
        return NULL;
    }

    if (NULL == (keyUseWith = xmlsec1mod_unwrap_xmlSecKeyUseWithPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyUseWithPtr);
        return NULL;
    }

    if (0 != xmlsec1_UnicodeOrBytesToXmlCharPtr(arg2, &application, NULL))
    {
        ENSURE_EXCEPTION_SET(xmlsec1_UnicodeOrBytesToXmlCharPtr);
        return NULL;
    }

    if (0 != xmlsec1_UnicodeOrBytesToXmlCharPtr(arg3, &identifier, NULL))
    {
        ENSURE_EXCEPTION_SET(xmlsec1_UnicodeOrBytesToXmlCharPtr);
        xmlFree(application);
        return NULL;
    }

    if (0 != xmlSecKeyUseWithSet(keyUseWith, application, identifier))
    {
        ENSURE_EXCEPTION_SET(xmlsec1_xmlSecKeyUseWithSet);
        xmlFree(application);
        xmlFree(identifier);
        return NULL;
    }

    xmlFree(application);
    xmlFree(identifier);

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyUseWithDebugDump(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecKeyUseWithPtr keyUseWith;
    PyFileObject * output;
    FILE * fp;

    static char * kwlist[] = {"keyUseWith", "output", NULL};

    arg1 = arg2 = NULL;
    keyUseWith = NULL;
    fp = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (keyUseWith = xmlsec1mod_unwrap_xmlSecKeyUseWithPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyUseWithPtr);
        return NULL;
    }

    if (!PyFile_Check(arg2))
    {
        PyErr_SetString(PyExc_TypeError, "output must be a file opened for writing");
    }

    output = (PyFileObject *)arg2;

    if (NULL == (fp = PyFile_AsFile(arg2)))
    {
        ENSURE_EXCEPTION_SET(PyFile_AsFile);
        return NULL;
    }

    Py_INCREF(arg1);
    PyFile_IncUseCount(output);
    Py_BEGIN_ALLOW_THREADS
    xmlSecKeyUseWithDebugDump(keyUseWith, fp);
    Py_END_ALLOW_THREADS
    PyFile_DecUseCount(output);
    Py_DECREF(arg1);

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyUseWithDebugXmlDump(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecKeyUseWithPtr keyUseWith;
    PyFileObject * output;
    FILE * fp;

    static char * kwlist[] = {"keyUseWith", "output", NULL};

    arg1 = arg2 = NULL;
    keyUseWith = NULL;
    fp = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (keyUseWith = xmlsec1mod_unwrap_xmlSecKeyUseWithPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyUseWithPtr);
        return NULL;
    }

    if (!PyFile_Check(arg2))
    {
        PyErr_SetString(PyExc_TypeError, "output must be a file opened for writing");
    }

    output = (PyFileObject *)arg2;

    if (NULL == (fp = PyFile_AsFile(arg2)))
    {
        ENSURE_EXCEPTION_SET(PyFile_AsFile);
        return NULL;
    }

    Py_INCREF(arg1);
    PyFile_IncUseCount(output);
    Py_BEGIN_ALLOW_THREADS
    xmlSecKeyUseWithDebugXmlDump(keyUseWith, fp);
    Py_END_ALLOW_THREADS
    PyFile_DecUseCount(output);
    Py_DECREF(arg1);

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyUseWithPtrListGetKlass(PyObject * self, PyObject * arg)
{
    xmlSecPtrListId klass;
    PyObject * ret;

    if (NULL == (klass = xmlSecKeyUseWithPtrListGetKlass()))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyUseWithPtrListGetKlass);
        return NULL;
    }

    if (NULL == (ret = xmlsec1mod_wrap_xmlSecPtrListId(klass)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_wrap_xmlSecPtrListId);
        return NULL;
    }

    return ret;
}



static PyObject * xmlsec1_xmlSecKeyReqInitialize(PyObject * self, PyObject * arg)
{
    xmlSecKeyReqPtr keyReq;

    if (NULL == (keyReq = xmlsec1mod_unwrap_xmlSecKeyReqPtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyReqPtr);
        return NULL;
    }

    if (0 != xmlSecKeyReqInitialize(keyReq))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyReqInitialize);
        return NULL;
    }

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyReqFinalize(PyObject * self, PyObject * arg)
{
    xmlSecKeyReqPtr keyReq;

    if (NULL == (keyReq = xmlsec1mod_unwrap_xmlSecKeyReqPtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyReqPtr);
        return NULL;
    }

    xmlSecKeyReqFinalize(keyReq);
    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyReqReset(PyObject * self, PyObject * arg)
{
    xmlSecKeyReqPtr keyReq;

    if (NULL == (keyReq = xmlsec1mod_unwrap_xmlSecKeyReqPtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyReqPtr);
        return NULL;
    }

    xmlSecKeyReqReset(keyReq);
    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyReqCopy(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecKeyReqPtr dst;
    xmlSecKeyReqPtr src;

    static char * kwlist[] = {"dst", "src", NULL};

    arg1 = arg2 = NULL;
    dst = src = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (dst = xmlsec1mod_unwrap_xmlSecKeyReqPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyReqPtr);
        return NULL;
    }

    if (NULL == (src = xmlsec1mod_unwrap_xmlSecKeyReqPtr(arg2)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyReqPtr);
        return NULL;
    }

    if (0 != xmlSecKeyReqCopy(dst, src))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyReqCopy);
        return NULL;
    }

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyReqMatchKey(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecKeyReqPtr keyReq;
    xmlSecKeyPtr key;

    static char * kwlist[] = {"keyReq", "key", NULL};

    arg1 = arg2 = NULL;
    keyReq = NULL;
    key = NULL;
    
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }
    
    if (NULL == (keyReq = xmlsec1mod_unwrap_xmlSecKeyReqPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyReqPtr);
        return NULL;
    }   
    
    if (NULL == (key = xmlsec1mod_unwrap_xmlSecKeyPtr(arg2)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyPtr);
        return NULL;
    }

    switch (xmlSecKeyReqMatchKey(keyReq, key))
    {
        case 0:
        {
            Py_RETURN_FALSE;
        }
        case 1:
        {
            Py_RETURN_TRUE;
        }
        default:
        {
            /* de nada */
        }
    }

    ENSURE_EXCEPTION_SET(xmlSecKeyReqMatchKey);
    return NULL;
}



static PyObject * xmlsec1_xmlSecKeyReqMatchKeyValue(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecKeyReqPtr keyReq;
    xmlSecKeyDataPtr value;
    
    static char * kwlist[] = {"keyReq", "value", NULL};
    
    arg1 = arg2 = NULL;
    keyReq = NULL;
    value = NULL;
   
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }
    
    if (NULL == (keyReq = xmlsec1mod_unwrap_xmlSecKeyReqPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyReqPtr);
        return NULL;
    }
   
    if (NULL == (value = xmlsec1mod_unwrap_xmlSecKeyDataPtr(arg2)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataPtr);
        return NULL;
    }

    switch (xmlSecKeyReqMatchKeyValue(keyReq, value))
    {
        case 0:
        {
            Py_RETURN_FALSE;
        }
        case 1:
        {
            Py_RETURN_TRUE;
        }
        default:
        {
            /* de nada */
        }
    }

    ENSURE_EXCEPTION_SET(xmlSecKeyReqMatchKeyValue);
    return NULL;
}



static PyObject * xmlsec1_xmlSecKeyReqDebugDump(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecKeyReqPtr keyReq;
    PyFileObject * output;
    FILE * fp;

    static char * kwlist[] = {"keyReq", "output", NULL};

    arg1 = arg2 = NULL;
    keyReq = NULL;
    fp = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (keyReq = xmlsec1mod_unwrap_xmlSecKeyReqPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyReqPtr);
        return NULL;
    }

    if (!PyFile_Check(arg2))
    {
        PyErr_SetString(PyExc_TypeError, "output must be a file opened for writing");
    }

    output = (PyFileObject *)arg2;

    if (NULL == (fp = PyFile_AsFile(arg2)))
    {
        ENSURE_EXCEPTION_SET(PyFile_AsFile);
        return NULL;
    }

    Py_INCREF(arg1);
    PyFile_IncUseCount(output);
    Py_BEGIN_ALLOW_THREADS
    xmlSecKeyReqDebugDump(keyReq, fp);
    Py_END_ALLOW_THREADS
    PyFile_DecUseCount(output);
    Py_DECREF(arg1);

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyReqDebugXmlDump(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecKeyReqPtr keyReq;
    PyFileObject * output;
    FILE * fp;

    static char * kwlist[] = {"keyReq", "output", NULL};

    arg1 = arg2 = NULL;
    keyReq = NULL;
    fp = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (keyReq = xmlsec1mod_unwrap_xmlSecKeyReqPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyReqPtr);
        return NULL;
    }

    if (!PyFile_Check(arg2))
    {
        PyErr_SetString(PyExc_TypeError, "output must be a file opened for writing");
    }

    output = (PyFileObject *)arg2;

    if (NULL == (fp = PyFile_AsFile(arg2)))
    {
        ENSURE_EXCEPTION_SET(PyFile_AsFile);
        return NULL;
    }

    Py_INCREF(arg1);
    PyFile_IncUseCount(output);
    Py_BEGIN_ALLOW_THREADS
    xmlSecKeyReqDebugXmlDump(keyReq, fp);
    Py_END_ALLOW_THREADS
    PyFile_DecUseCount(output);
    Py_DECREF(arg1);

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyCreate(PyObject * self, PyObject * arg)
{
    xmlSecKeyPtr key;
    PyObject * ret;

    if (NULL == (key = xmlSecKeyCreate()))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyCreate);
        return NULL;
    }

    if (NULL == (ret = xmlsec1mod_wrap_xmlSecKeyPtr(key)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_wrap_xmlSecKeyPtr);
        xmlSecKeyDestroy(key);
        return NULL;
    }

    return ret;
}



static PyObject * xmlsec1_xmlSecKeyDestroy(PyObject * self, PyObject * arg)
{
    xmlSecKeyPtr key;

    if (NULL == (key = xmlsec1mod_unwrap_xmlSecKeyPtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyPtr);
        return NULL;
    }

    xmlSecKeyDestroy(key);
    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyEmpty(PyObject * self, PyObject * arg)
{
    xmlSecKeyPtr key;

    if (NULL == (key = xmlsec1mod_unwrap_xmlSecKeyPtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyPtr);
        return NULL;
    }

    xmlSecKeyEmpty(key);
    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyDuplicate(PyObject * self, PyObject * arg)
{
    xmlSecKeyPtr key;
    xmlSecKeyPtr ptr;
    PyObject * ret;

    if (NULL == (key = xmlsec1mod_unwrap_xmlSecKeyPtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyPtr);
        return NULL;
    }

    if (NULL == (ptr = xmlSecKeyDuplicate(key)))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyDuplicate);
        return NULL;
    }

    if (NULL == (ret = xmlsec1mod_wrap_xmlSecKeyPtr(ptr)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_wrap_xmlSecKeyPtr);
        xmlSecKeyDestroy(ptr);
        return NULL;
    }

    return ret;
}



static PyObject * xmlsec1_xmlSecKeyCopy(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecKeyPtr keyDst;
    xmlSecKeyPtr keySrc;

    static char * kwlist[] = {"keyDst", "keySrc", NULL};

    arg1 = arg2 = NULL;
    keyDst = keySrc = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (keyDst = xmlsec1mod_unwrap_xmlSecKeyPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyPtr);
        return NULL;
    }

    if (NULL == (keySrc = xmlsec1mod_unwrap_xmlSecKeyPtr(arg2)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyPtr);
        return NULL;
    }

    if (0 != xmlSecKeyCopy(keyDst, keySrc))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyCopy);
        return NULL;
    }

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyGetName(PyObject * self, PyObject * arg)
{
    xmlSecKeyPtr key;
    const xmlChar * name;
    PyObject * ret;

    if (NULL == (key = xmlsec1mod_unwrap_xmlSecKeyPtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyPtr);
        return NULL;
    }

    if (NULL == (name = xmlSecKeyGetName(key)))
    {
        if (PyErr_Occurred())
        {
            return NULL;
        }

        Py_RETURN_NONE;
    }

    if (NULL == (ret = PyBytes_FromString((const char *)name)))
    {
        ENSURE_EXCEPTION_SET(PyBytes_FromString);
        return NULL;
    }

    return ret;
}



static PyObject * xmlsec1_xmlSecKeySetName(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecKeyPtr key;
    xmlChar * name;

    static char * kwlist[] = {"key", "name", NULL};

    arg1 = arg2 = NULL;
    key = NULL;
    name = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (key = xmlsec1mod_unwrap_xmlSecKeyPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyPtr);
        return NULL;
    }

    if (Py_None == arg2)
    {
        if (0 != xmlSecKeySetName(key, NULL))
        {
            ENSURE_EXCEPTION_SET(xmlSecKeySetName);
            return NULL;
        }

        Py_RETURN_NONE;
    }

    if (0 != xmlsec1_UnicodeOrBytesToXmlCharPtr(arg2, &name, NULL))
    {
        ENSURE_EXCEPTION_SET(xmlsec1_UnicodeOrBytesToXmlCharPtr);
        return NULL;
    }

    if (0 != xmlSecKeySetName(key, name))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeySetName);
        xmlFree(name);
        return NULL;
    }

    xmlFree(name);
    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyGetType(PyObject * self, PyObject * arg)
{
    xmlSecKeyPtr key;

    if (NULL == (key = xmlsec1mod_unwrap_xmlSecKeyPtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyPtr);
        return NULL;
    }

    return Py_BuildValue("I", xmlSecKeyGetType(key));
}



static PyObject * xmlsec1_xmlSecKeyGetValue(PyObject * self, PyObject * arg)
{
    xmlSecKeyPtr key;
    xmlSecKeyDataPtr ptr;
    PyObject * ret;

    if (NULL == (key = xmlsec1mod_unwrap_xmlSecKeyPtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyPtr);
        return NULL;
    }

    if (NULL == (ptr = xmlSecKeyGetValue(key)))
    {
        if (PyErr_Occurred())
        {
            return NULL;
        }

        Py_RETURN_NONE;
    }

    if (NULL == (ret = xmlsec1mod_wrap_xmlSecKeyDataPtr(ptr)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_wrap_xmlSecKeyDataPtr);
        return NULL;
    }

    return ret;
}



static PyObject * xmlsec1_xmlSecKeySetValue(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecKeyPtr key;
    xmlSecKeyDataPtr value;

    static char * kwlist[] = {"key", "value", NULL};

    arg1 = arg2 = NULL;
    key = NULL;
    value = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (key = xmlsec1mod_unwrap_xmlSecKeyPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyPtr);
        return NULL;
    }

    if (Py_None == arg2)
    {
        if (0 != xmlSecKeySetValue(key, NULL))
        {
            ENSURE_EXCEPTION_SET(xmlSecKeySetValue);
            return NULL;
        }

        Py_RETURN_NONE;
    }

    if (NULL == (value = xmlsec1mod_unwrap_xmlSecKeyDataPtr(arg2)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataPtr);
        return NULL;
    }

    if (0 != xmlSecKeySetValue(key, value))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeySetValue);
        return NULL;
    }

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyGetData(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecKeyPtr key;
    xmlSecKeyDataId dataId;
    xmlSecKeyDataPtr ptr;
    PyObject * ret;

    static char * kwlist[] = {"key", "dataId", NULL};

    arg1 = arg2 = ret = NULL;
    key = NULL;
    dataId = NULL;
    ptr = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (key = xmlsec1mod_unwrap_xmlSecKeyPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyPtr);
        return NULL;
    }

    if (NULL == (dataId = xmlsec1mod_unwrap_xmlSecKeyDataId(arg2)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataId);
        return NULL;
    }

    ptr = xmlSecKeyGetData(key, dataId);

    if (NULL == ptr && PyErr_Occurred())
    {
        return NULL;
    }

    if (NULL == ptr)
    {
        Py_RETURN_NONE;
    }

    if (NULL == (ret = xmlsec1mod_wrap_xmlSecKeyDataPtr(ptr)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_wrap_xmlSecKeyDataPtr);
        return NULL;
    }

    return ret;
}



static PyObject * xmlsec1_xmlSecKeyEnsureData(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecKeyPtr key;
    xmlSecKeyDataId dataId;
    xmlSecKeyDataPtr ptr;
    PyObject * ret;

    static char * kwlist[] = {"key", "dataId", NULL};

    arg1 = arg2 = ret = NULL;
    key = NULL;
    dataId = NULL;
    ptr = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (key = xmlsec1mod_unwrap_xmlSecKeyPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyPtr);
        return NULL;
    }

    if (NULL == (dataId = xmlsec1mod_unwrap_xmlSecKeyDataId(arg2)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataId);
        return NULL;
    }

    if (NULL == (ptr = xmlSecKeyEnsureData(key, dataId)))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyEnsureData);
        return NULL;
    }

    if (NULL == (ret = xmlsec1mod_wrap_xmlSecKeyDataPtr(ptr)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_wrap_xmlSecKeyDataPtr);
        /* we just don't know if it was created or not, but either way it's managed with the key now */
        return NULL;
    }

    return ret;
}



static PyObject * xmlsec1_xmlSecKeyAdoptData(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecKeyPtr key;
    xmlSecKeyDataPtr data;

    static char * kwlist[] = {"key", "data", NULL};

    arg1 = arg2 = NULL;
    key = NULL;
    data = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (key = xmlsec1mod_unwrap_xmlSecKeyPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyPtr);
        return NULL;
    }

    if (NULL == (data = xmlsec1mod_unwrap_xmlSecKeyDataPtr(arg2)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataPtr);
        return NULL;
    }

    if (0 != xmlSecKeyAdoptData(key, data))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyAdoptData);
        return NULL;
    }

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyDebugDump(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecKeyPtr key;
    PyFileObject * output;
    FILE * fp;

    static char * kwlist[] = {"key", "output", NULL};

    arg1 = arg2 = NULL;
    key = NULL;
    fp = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (key = xmlsec1mod_unwrap_xmlSecKeyPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyPtr);
        return NULL;
    }

    if (!PyFile_Check(arg2))
    {
        PyErr_SetString(PyExc_TypeError, "output must be a file opened for writing");
    }

    output = (PyFileObject *)arg2;

    if (NULL == (fp = PyFile_AsFile(arg2)))
    {
        ENSURE_EXCEPTION_SET(PyFile_AsFile);
        return NULL;
    }

    Py_INCREF(arg1);
    PyFile_IncUseCount(output);
    Py_BEGIN_ALLOW_THREADS
    xmlSecKeyDebugDump(key, fp);
    Py_END_ALLOW_THREADS
    PyFile_DecUseCount(output);
    Py_DECREF(arg1);

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyDebugXmlDump(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecKeyPtr key;
    PyFileObject * output;
    FILE * fp;

    static char * kwlist[] = {"key", "output", NULL}; 

    arg1 = arg2 = NULL;
    key = NULL;
    fp = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (key = xmlsec1mod_unwrap_xmlSecKeyPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyPtr);
        return NULL;
    }

    if (!PyFile_Check(arg2))
    {
        PyErr_SetString(PyExc_TypeError, "output must be a file opened for writing");
    }

    output = (PyFileObject *)arg2;

    if (NULL == (fp = PyFile_AsFile(arg2)))
    {
        ENSURE_EXCEPTION_SET(PyFile_AsFile);
        return NULL;
    }

    Py_INCREF(arg1);
    PyFile_IncUseCount(output);
    Py_BEGIN_ALLOW_THREADS
    xmlSecKeyDebugXmlDump(key, fp);
    Py_END_ALLOW_THREADS
    PyFile_DecUseCount(output);
    Py_DECREF(arg1);

    Py_RETURN_NONE;
}



static PyObject * xmlsec1_xmlSecKeyGenerate(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    int arg2;
    int arg3;
    xmlSecKeyDataId dataId;
    xmlSecSize sizeBits;
    xmlSecKeyDataType kdtype;
    xmlSecKeyPtr ptr;
    PyObject * ret;

    static char * kwlist[] = {"dataId", "sizeBits", "kdtype", NULL};

    arg1 = ret = NULL;
    arg2 = arg3 = 0;
    dataId = NULL;
    sizeBits = 0;
    kdtype = xmlSecKeyDataTypeUnknown;
    ptr = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "Oii", kwlist, &arg1, &arg2, &arg3))
    {
        return NULL;
    }

    if (NULL == (dataId = xmlsec1mod_unwrap_xmlSecKeyDataId(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataId);
        return NULL;
    }

    sizeBits = (xmlSecSize)arg2;
    kdtype = (xmlSecKeyDataType)arg3;

    if (NULL == (ptr = xmlSecKeyGenerate(dataId, sizeBits, kdtype)))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyGenerate);
        return NULL;
    }

    if (NULL == (ret = xmlsec1mod_wrap_xmlSecKeyPtr(ptr)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_wrap_xmlSecKeyPtr);
        xmlSecKeyDestroy(ptr);
        return NULL;
    }

    return ret;
}



static PyObject * xmlsec1_xmlSecKeyGenerateByName(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    int arg2;
    int arg3;
    xmlChar * name;
    xmlSecSize sizeBits;
    xmlSecKeyDataType kdtype;
    xmlSecKeyPtr ptr;
    PyObject * ret;

    static char * kwlist[] = {"name", "sizeBits", "kdtype", NULL};

    arg1 = ret = NULL;
    arg2 = arg3 = 0;
    name = NULL;
    sizeBits = 0;
    kdtype = xmlSecKeyDataTypeUnknown;
    ptr = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "Oii", kwlist, &arg1, &arg2, &arg3))
    {
        return NULL;
    }

    if (0 != xmlsec1_UnicodeOrBytesToXmlCharPtr(arg1, &name, NULL))
    {
        ENSURE_EXCEPTION_SET(xmlsec1_UnicodeOrBytesToXmlCharPtr);
        return NULL;
    }

    sizeBits = (xmlSecSize)arg2;
    kdtype = (xmlSecKeyDataType)arg3;

    if (NULL == (ptr = xmlSecKeyGenerateByName(name, sizeBits, kdtype)))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyGenerateByName);
        xmlFree(name);
        return NULL;
    }

    xmlFree(name);

    if (NULL == (ret = xmlsec1mod_wrap_xmlSecKeyPtr(ptr)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_wrap_xmlSecKeyPtr);
        xmlSecKeyDestroy(ptr);
        return NULL;
    }

    return ret;
}



static PyObject * xmlsec1_xmlSecKeyMatch(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    PyObject * arg3;
    xmlSecKeyPtr key;
    xmlChar * name;
    xmlSecKeyReqPtr keyReq;

    static char * kwlist[] = {"key", "name", "keyReq", NULL};

    arg1 = arg2 = arg3 = NULL;
    key = NULL;
    name = NULL;
    keyReq = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOO", kwlist, &arg1, &arg2, &arg3))
    {
        return NULL;
    }

    if (NULL == (key = xmlsec1mod_unwrap_xmlSecKeyPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyPtr);
        return NULL;
    }

    if (NULL == (keyReq = xmlsec1mod_unwrap_xmlSecKeyReqPtr(arg3)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyReqPtr);
        return NULL;
    }

    if (Py_None != arg2)
    {
        if (0 != xmlsec1_UnicodeOrBytesToXmlCharPtr(arg2, &name, NULL))
        {
            ENSURE_EXCEPTION_SET(xmlsec1_UnicodeOrBytesToXmlCharPtr);
            return NULL;
        }
    }

    switch (xmlSecKeyMatch(key, name, keyReq))
    {
        case 0:
        {
            xmlFree(name);
            Py_RETURN_FALSE;
        }
        case 1:
        {
            xmlFree(name);
            Py_RETURN_TRUE;
        }
        default:
        {
            xmlFree(name);
            /* drop through */
        }
    }

    ENSURE_EXCEPTION_SET(xmlSecKeyMatch);
    return NULL;
}



static PyObject * xmlsec1_xmlSecKeyReadBuffer(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecKeyDataId dataId;
    xmlSecBufferPtr buffer;
    xmlSecKeyPtr ptr;
    PyObject * ret;

    static char * kwlist[] = {"dataId", "buffer", NULL};

    arg1 = arg2 = ret = NULL;
    dataId = NULL;
    buffer = NULL;
    ptr = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (dataId = xmlsec1mod_unwrap_xmlSecKeyDataId(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataId);
        return NULL;
    }

    if (NULL == (buffer = xmlsec1mod_unwrap_xmlSecBufferPtr(arg2)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecBufferPtr);
        return NULL;
    }

    if (NULL == (ptr = xmlSecKeyReadBuffer(dataId, buffer)))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyReadBuffer);
        return NULL;
    }

    if (NULL == (ret = xmlsec1mod_wrap_xmlSecKeyPtr(ptr)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_wrap_xmlSecKeyPtr);
        xmlSecKeyDestroy(ptr);
        return NULL;
    }

    return ret;
}



static PyObject * xmlsec1_xmlSecKeyReadBinaryFile(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    xmlSecKeyDataId dataId;
    char * filename;
    xmlSecKeyPtr ptr;
    PyObject * ret;

    static char * kwlist[] = {"dataId", "filename", NULL};

    arg1 = ret = NULL;
    dataId = NULL;
    filename = NULL;
    ptr = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "Os", kwlist, &arg1, &filename))
    {
        return NULL;
    }

    if (NULL == (dataId = xmlsec1mod_unwrap_xmlSecKeyDataId(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataId);
        return NULL;
    }

    if (NULL == (ptr = xmlSecKeyReadBinaryFile(dataId, filename)))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyReadBinaryFile);
        return NULL;
    }

    if (NULL == (ret = xmlsec1mod_wrap_xmlSecKeyPtr(ptr)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_wrap_xmlSecKeyPtr);
        xmlSecKeyDestroy(ptr);
        return NULL;
    }

    return ret;
}



static PyObject * xmlsec1_xmlSecKeyReadMemory(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecKeyDataId dataId;
    xmlSecByte * data;
    xmlSecSize dataSize;
    xmlSecKeyPtr ptr;
    PyObject * ret;

    static char * kwlist[] = {"dataId", "buffer", NULL};

    arg1 = arg2 = ret = NULL;
    dataId = NULL;
    data = NULL;
    dataSize = 0;
    ptr = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (dataId = xmlsec1mod_unwrap_xmlSecKeyDataId(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataId);
        return NULL;
    }

    if (0 != xmlsec1_ByteArrayOrBytesToXmlSecBytes(arg2, &data, &dataSize))
    {
        ENSURE_EXCEPTION_SET(xmlsec1_ByteArrayOrBytesToXmlSecBytes);
        return NULL;
    }

    if (NULL == (ptr = xmlSecKeyReadMemory(dataId, data, dataSize)))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyReadMemory);
        PyMem_Del(data);
        return NULL;
    }

    PyMem_Del(data);

    if (NULL == (ret = xmlsec1mod_wrap_xmlSecKeyPtr(ptr)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_wrap_xmlSecKeyPtr);
        xmlSecKeyDestroy(ptr);
        return NULL;
    }

    return ret;
}



static PyObject * xmlsec1_xmlSecKeyIsValid(PyObject * self, PyObject * arg)
{
    xmlSecKeyPtr key;

    if (NULL == (key = xmlsec1mod_unwrap_xmlSecKeyPtr(arg)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyPtr);
        return NULL;
    }

    if (xmlSecKeyIsValid(key))
    {
        Py_RETURN_TRUE;
    }

    Py_RETURN_FALSE;
}



static PyObject * xmlsec1_xmlSecKeyCheckId(PyObject * self, PyObject * args, PyObject * kwds)
{
    PyObject * arg1;
    PyObject * arg2;
    xmlSecKeyPtr key;
    xmlSecKeyDataId keyId;

    static char * kwlist[] = {"key", "keyId", NULL};

    arg1 = arg2 = NULL;
    key = NULL;
    keyId = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &arg1, &arg2))
    {
        return NULL;
    }

    if (NULL == (key = xmlsec1mod_unwrap_xmlSecKeyPtr(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyPtr);
        return NULL;
    }

    if (NULL == (keyId = xmlsec1mod_unwrap_xmlSecKeyDataId(arg1)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_unwrap_xmlSecKeyDataId);
        return NULL;
    }

    if (xmlSecKeyCheckId(key, keyId))
    {
        Py_RETURN_TRUE;
    }

    Py_RETURN_FALSE;
}



static PyObject * xmlsec1_xmlSecKeyPtrListGetKlass(PyObject * self, PyObject * arg)
{
    xmlSecPtrListId klass;
    PyObject * ret;

    if (NULL == (klass = xmlSecKeyPtrListGetKlass()))
    {
        ENSURE_EXCEPTION_SET(xmlSecKeyPtrListGetKlass);
        return NULL;
    }

    if (NULL == (ret = xmlsec1mod_wrap_xmlSecPtrListId(klass)))
    {
        ENSURE_EXCEPTION_SET(xmlsec1mod_wrap_xmlSecPtrListId);
        return NULL;
    }

    return ret;
}


#if 0
-- typedef xmlSecKeyUsage;
-- #define xmlSecKeyUsageSign
-- #define xmlSecKeyUsageVerify
-- #define xmlSecKeyUsageEncrypt
-- #define xmlSecKeyUsageDecrypt
-- #define xmlSecKeyUsageKeyExchange
-- #define xmlSecKeyUsageAny
-- int xmlSecKeyUseWithInitialize(xmlSecKeyUseWithPtr keyUseWith);
-- void xmlSecKeyUseWithFinalize(xmlSecKeyUseWithPtr keyUseWith);
-- void xmlSecKeyUseWithReset(xmlSecKeyUseWithPtr keyUseWith);
-- int xmlSecKeyUseWithCopy(xmlSecKeyUseWithPtr dst, xmlSecKeyUseWithPtr src);
-- xmlSecKeyUseWithPtr xmlSecKeyUseWithCreate(const xmlChar *application, const xmlChar *identifier);
-- xmlSecKeyUseWithPtr xmlSecKeyUseWithDuplicate(xmlSecKeyUseWithPtr keyUseWith);
-- void xmlSecKeyUseWithDestroy(xmlSecKeyUseWithPtr keyUseWith);
-- int xmlSecKeyUseWithSet(xmlSecKeyUseWithPtr keyUseWith, const xmlChar *application, const xmlChar *identifier);
-- void xmlSecKeyUseWithDebugDump(xmlSecKeyUseWithPtr keyUseWith, FILE *output);
-- void xmlSecKeyUseWithDebugXmlDump(xmlSecKeyUseWithPtr keyUseWith, FILE *output);
-- struct xmlSecKeyUseWith;

-- #define xmlSecKeyUseWithPtrListId
-- xmlSecPtrListId xmlSecKeyUseWithPtrListGetKlass(void);

-- struct xmlSecKeyReq;
-- int xmlSecKeyReqInitialize(xmlSecKeyReqPtr keyReq);
-- void xmlSecKeyReqFinalize(xmlSecKeyReqPtr keyReq);
-- void xmlSecKeyReqReset(xmlSecKeyReqPtr keyReq);
-- int xmlSecKeyReqCopy(xmlSecKeyReqPtr dst, xmlSecKeyReqPtr src);
-- int xmlSecKeyReqMatchKey(xmlSecKeyReqPtr keyReq, xmlSecKeyPtr key);
-- int xmlSecKeyReqMatchKeyValue(xmlSecKeyReqPtr keyReq, xmlSecKeyDataPtr value);
-- void xmlSecKeyReqDebugDump(xmlSecKeyReqPtr keyReq, FILE *output);
-- void xmlSecKeyReqDebugXmlDump(xmlSecKeyReqPtr keyReq, FILE *output);

-- struct xmlSecKey;
-- xmlSecKeyPtr xmlSecKeyCreate(void);
-- void xmlSecKeyDestroy(xmlSecKeyPtr key);
-- void xmlSecKeyEmpty(xmlSecKeyPtr key);
-- xmlSecKeyPtr xmlSecKeyDuplicate(xmlSecKeyPtr key);
-- int xmlSecKeyCopy(xmlSecKeyPtr keyDst, xmlSecKeyPtr keySrc);
-- const xmlChar* xmlSecKeyGetName(xmlSecKeyPtr key);
-- int xmlSecKeySetName(xmlSecKeyPtr key, const xmlChar *name);
-- xmlSecKeyDataType xmlSecKeyGetType(xmlSecKeyPtr key);
-- xmlSecKeyDataPtr xmlSecKeyGetValue(xmlSecKeyPtr key);
-- int xmlSecKeySetValue(xmlSecKeyPtr key, xmlSecKeyDataPtr value);
-- xmlSecKeyDataPtr xmlSecKeyGetData(xmlSecKeyPtr key, xmlSecKeyDataId dataId);
-- xmlSecKeyDataPtr xmlSecKeyEnsureData(xmlSecKeyPtr key, xmlSecKeyDataId dataId);
-- int xmlSecKeyAdoptData(xmlSecKeyPtr key, xmlSecKeyDataPtr data);
-- void xmlSecKeyDebugDump(xmlSecKeyPtr key, FILE *output);
-- void xmlSecKeyDebugXmlDump(xmlSecKeyPtr key, FILE *output);
-- xmlSecKeyPtr xmlSecKeyGenerate(xmlSecKeyDataId dataId, xmlSecSize sizeBits, xmlSecKeyDataType type);
-- xmlSecKeyPtr xmlSecKeyGenerateByName(const xmlChar *name, xmlSecSize sizeBits, xmlSecKeyDataType type);
-- int xmlSecKeyMatch(xmlSecKeyPtr key, const xmlChar *name, xmlSecKeyReqPtr keyReq);
-- xmlSecKeyPtr xmlSecKeyReadBuffer(xmlSecKeyDataId dataId, xmlSecBuffer *buffer);
-- xmlSecKeyPtr xmlSecKeyReadBinaryFile(xmlSecKeyDataId dataId, const char *filename);
-- xmlSecKeyPtr xmlSecKeyReadMemory(xmlSecKeyDataId dataId, const xmlSecByte *data, xmlSecSize dataSize);
-- #define xmlSecKeyIsValid(key)
-- #define xmlSecKeyCheckId(key, keyId)

-- #define xmlSecKeyPtrListId
-- xmlSecPtrListId xmlSecKeyPtrListGetKlass(void);

#endif

#endif
